
    //需要图色就解开截图权限
    // let request = image.requestScreenCapture(10000, 0);
    // if (!request) {
    //     request = image.requestScreenCapture(10000, 0);
    // }
    // logd("申请截图结果... " + request)
    // if (!request) {
    //     loge("申请截图权限失败,检查是否开启后台弹出,悬浮框等权限")
    //     exit()
    // }
    // sleep(1000);
    var version = "1.0.001"; //当前版本号
    toast("当前版本 -> " + version);
    device.keepScreenOn();//保持屏幕唤醒
    ui.showLogWindow();//显示日志
    const x = device.getScreenWidth(), y = device.getScreenHeight(); //屏幕的横坐标 x //屏幕的纵坐标 y
    var m = {
        "x": x / 1.1, "y": y / 1.7,
    }
    setCtrlViewSizeEx(m);//设置启停位置
    showCtrlWindow();//显示启停
    setTimeout(function () {
        ui.closeLogWindow();
    }, 5000); //5秒后关闭日志
    var toastExtra = {
        "x": x / 1,
        "y": y / 1,
        "width": x / 7,
        "height": y / 7,
        "duration": 120000,
        "textColor": "#1dfc04",
        "draggable": false
    }//toast窗口位置
    var 编号 = readConfigString("编号");//读取字符串数据//readConfigLong readConfigLong是读取数字?
    var 账号 = readConfigString("账号");//读取字符串数据
    var 密码 = readConfigString("密码");//读取字符串数据

    var 单选一 = readConfigString("one");
    var 单选二 = readConfigString("two");
    var 单选三 = readConfigString("three");
    var 单选四 = readConfigString("four");

    thread.execAsync(function () {

        for (; ;) {

            removeNodeFlag(0);
            sleep(100)
            if (查找节点点击("当前应用暂不支持", text("当前应用暂不支持"), 111, 100)) {
                logd("当前应用暂不支持")
                back()
                sleep(3000)
            }
            if (查找节点点击("拒绝", text("拒绝"), 1, 100)) {
                logd("拒绝")
                sleep(100)
            }
            if (查找节点点击("点击重试", text("点击重试"), 1, 100)) {
                logd("点击重试")
                sleep(100)
            }
            if (查找节点点击("下次再说", text("下次再说"), 1, 100)) {
                logd("下次再说")
                sleep(100)
            }
            if (查找节点点击("打开", text("打开"), 1, 100)) {
                logd("打开")
                sleep(3000)
            }
            if (查找节点点击("关闭应用", text("关闭应用"), 1, 100)) {
                logd("关闭应用")
                sleep(3000)
            }
            if (查找节点点击("使用帮助", text("使用帮助"), 1000, 100)) {
                back()
                sleep(2000)
            }
            if (查找节点点击("选择文件", text("选择文件"), 1000, 100)) {
                logd("选择文件")
                back()
                sleep(2000)
            }
            if (查找节点点击("文件中转站", text("文件中转站"), 1000, 100)) {
                logd("文件中转站")
                back()
                sleep(2000)
            }
            if (查找节点点击("上传本机APP", text("上传本机APP"), 1000, 100)) {
                logd("上传本机APP")
                back()
                sleep(1000)
            }
            if (查找节点点击("继续", text("继 续"), 1, 100)) {
                logd("继续")
                sleep(2000)
            }

            if (查找节点点击("允许", text("允许"), 1, 100)) {
                logd("允许")
                sleep(2000)
            }

            if (查找节点点击("打开方式", text("打开方式"), 1000, 100)) {
                logd("打开方式")
                sleep(100)
                if (查找节点点击("淘宝", text("淘宝"), 1, 1000)) {
                    logd("淘宝")
                    sleep(1000)
                    if (查找节点点击("始终", text("始终"), 1, 1000)) {
                        logd("始终")
                        sleep(1000)
                    }
                }
                if (查找节点点击("支付宝", text("支付宝"), 1, 1000)) {
                    logd("支付宝")
                    sleep(1000)
                    if (查找节点点击("始终", text("始终"), 1, 1000)) {
                        logd("始终")
                        sleep(1000)
                    }
                }
            }
            if (查找节点点击("退出访问", text("退出访问"), 1, 500)) {
                logd("退出访问")
                sleep(100)
            }

            let TB滑块 = getOneNodeInfo(text("验证码拦截"), 3 * 1000)
            if (TB滑块) {
                let 带盾的滑块 = getOneNodeInfo(text("为了您的账号安全，需要进行安全校验"), 1500)
                if (带盾的滑块) {
                    moveFun(x * 0.138, y * 0.714, x * 0.958, y * 0.711, 2240, 4500, 800)
                    sleep(5500);
                    let 没有划过滑块 = getOneNodeInfo(text("验证码拦截"), 1000)
                    if (没有划过滑块) {
                        clickPoint(x * 0.501, y * 0.71);
                        sleep(1000);
                        moveFun(x * 0.138, y * 0.714, x * 0.958, y * 0.711, 2240, 4500, 800)
                        sleep(5500);
                        let 没有划过滑块2 = getOneNodeInfo(text("验证码拦截"), 1000)
                        if (没有划过滑块2) {
                            clickPoint(x * 0.501, y * 0.71);
                            sleep(1000);
                            moveFun(x * 0.138, y * 0.714, x * 0.958, y * 0.711, 2240, 4500, 800)
                            sleep(5500);
                            let 没有划过滑块3 = getOneNodeInfo(text("验证码拦截"), 1000)
                            if (没有划过滑块3) {
                                sleep(5000)
                                back()
                                sleep(1000);
                            }
                        }

                    }
                } else {
                    moveFun(x * 0.143, y * 0.667, x * 0.958, y * 0.666, 2240, 4500, 800)
                    sleep(5500);
                    let 没有划过滑块 = getOneNodeInfo(text("验证码拦截"), 1000)
                    if (没有划过滑块) {
                        clickPoint(x * 0.480, y * 0.651);
                        sleep(1000);
                        moveFun(x * 0.143, y * 0.667, x * 0.958, y * 0.666, 2240, 4500, 800)
                        sleep(5500);
                        let 没有划过滑块2 = getOneNodeInfo(text("验证码拦截"), 1000)
                        if (没有划过滑块2) {
                            clickPoint(x * 0.480, y * 0.651);
                            sleep(1000);
                            moveFun(x * 0.143, y * 0.667, x * 0.958, y * 0.666, 2240, 4500, 800)
                            sleep(5500);
                            let 没有划过滑块3 = getOneNodeInfo(text("验证码拦截"), 1000)
                            if (没有划过滑块3) {
                                sleep(20000)
                                back()
                                sleep(1000);
                            }
                        }

                    }
                }

            }

        }

    });//弹窗线程

    任务1()

    function 任务1() {
        logd("执行小鱼取关")
        sleep(100)
        let request = image.requestScreenCapture(10000, 0);
        if (!request) {
            request = image.requestScreenCapture(10000, 0);
        }
        logd("申请截图结果... " + request)
        if (!request) {
            loge("申请截图权限失败,检查是否开启后台弹出,悬浮框等权限")
            exit()
        }
        sleep(1000);
        let 找图文件夹 = file.exists("/sdcard/找图/");
        sleep(100);
        if (找图文件夹 == false) {
            var t = file.mkdirs("/sdcard/找图/");
            toast(t);
            sleep(1000)
        }
        检查图片("yiguanzhu")
        检查图片("hufen")
        检查图片("quguanqueding")
        检查图片("3.6yiguanzhu")
        检查图片("3.6hufen")
        检查图片("3.6quguanqueding")
        检查图片("5.9yiguanzhu")
        检查图片("5.9hufen")
        检查图片("5.9quguanqueding")

        for (; ;) {
            try {
                for (; ;) {
                    try {
                        toast("开始执行小鱼")
                        sleep(2000)
                        let 我的关注界面 = {
                            className: "com.taobao.fleamarket.home.activity.InitActivity",
                            uri: "https://h5.m.goofish.com/wow/moyu/moyu-project/idle-community/pages/home?isOldFriendly=false&_from__=main",
                            pkg: "com.taobao.idlefish",
                        }
                        utils.openActivity(我的关注界面);
                        sleep(10000)
                        if (查找节点点击("我的关注界面", text("关注的人"), 1, 1100)) {
                            logd("我的关注界面")
                            sleep(100)
                        }
                        for (let i = 0; i < 45; i++) {
                            toast("第:" + i + "次", toastExtra);
                            sleep(100);


                            let TB滑块 = getOneNodeInfo(text("验证码拦截"), 100)
                            if (TB滑块) {
                                for (; ;) {
                                    let TB滑块 = getOneNodeInfo(text("验证码拦截"), 500)
                                    if (TB滑块) {
                                        logd("等待验证")
                                        sleep(20000)
                                    } else {
                                        break
                                    }
                                }
                            } else {
                                logd("没有验证码拦截")
                                sleep(100)
                            }

                            if (找图点击("yiguanzhu", 1)) {
                                logd("已关注")
                                sleep(2000)
                            }
                            if (找图点击("hufen", 1)) {
                                logd("互粉")
                                sleep(2000)
                            }
                            if (找图点击("quguanqueding", 1)) {
                                logd("取关确定")
                                sleep(2000)
                            }
                            if (找图点击("3.6yiguanzhu", 1)) {
                                logd("已关注")
                                sleep(2000)
                            }
                            if (找图点击("3.6hufen", 1)) {
                                logd("互粉")
                                sleep(2000)
                            }
                            if (找图点击("3.6quguanqueding", 1)) {
                                logd("取关确定")
                                sleep(2000)
                            }
                            if (找图点击("5.9yiguanzhu", 1)) {
                                logd("已关注")
                                sleep(2000)
                            }
                            if (找图点击("5.9hufen", 1)) {
                                logd("互粉")
                                sleep(2000)
                            }
                            if (找图点击("5.9quguanqueding", 1)) {
                                logd("取关确定")
                                sleep(2000)
                            }
                            if (查找节点点击("人物里面已关注", desc("已关注"), 1000, 100)) {
                                logd("人物里面已关注")
                                sleep(100)
                                back();
                                sleep(2000);
                            }

                            if (查找节点点击("用户违规", descMatch("^该用户因违反法规或闲鱼相关规则账号已被处置"), 1000, 100)) {
                                logd("用户违规")
                                sleep(100)
                                back();
                                sleep(2000);
                            }
                            if (查找节点点击("人物里面未关注", desc("关注"), 1000, 100)) {
                                logd("人物里面未关注")
                                sleep(100)
                                back();
                                sleep(2000);
                            }
                            if (查找节点点击("你还没有关注的人呢", text("你还没有关注的人呢"), 1000, 100)) {
                                logw("取关完成")
                                sleep(100)
                                ui.showLogWindow();//显示日志
                                sleep(100)
                                exit()
                            }

                            if (查找节点点击("我的关注界面", text("关注的人"), 11, 100)) {
                                logd("我的关注界面")
                                sleep(100)
                                swipeToPoint(x * 0.51, y * 0.82, x * 0.47, y * 0.68, 1200)
                                sleep(2000);
                            } else {
                                let 我的关注界面 = {
                                    className: "com.taobao.fleamarket.home.activity.InitActivity",
                                    uri: "https://h5.m.goofish.com/wow/moyu/moyu-project/idle-community/pages/home?isOldFriendly=false&_from__=main",
                                    pkg: "com.taobao.idlefish",
                                }
                                utils.openActivity(我的关注界面);
                                sleep(10000)
                            }

                        }

                        停止应用("com.taobao.idlefish")
                        sleep(3000)
                        for (let i = 0; i < (random(400, 500)); i++) {
                            toast("休息" + i + "分钟", toastExtra);
                            sleep(60000);
                        }


                    } catch (e) {
                        logw("出错")
                        sleep(1000)
                    }

                }
            } catch (e) {
                logw("出错")
                sleep(1000)
            }
        }
    }


    function 热更新() {
        for (let i = 0; i < 30; i++) {
            let cm = context.getSystemService(context.CONNECTIVITY_SERVICE);
            let net = cm.getActiveNetworkInfo();
            if (net == null || !net.isAvailable()) {
                toast("网络未连接");
                sleep(1000)
                toast("网络未连接");
                sleep(1000)
                utils.openIntentAction("android.settings.WIFI_SETTINGS")
                toast("进入wifi选项")
                sleep(2000)
                for (let i = 0; i < 30; i++) {
                    if (查找节点点击("关", text("关"), 1, 3100)) {
                        logd("关")
                        sleep(10000)
                        break
                    }
                    if (查找节点点击("高级", text("高级"), 1, 3100)) {
                        logd("高级")
                        sleep(1100)
                    }
                    if (查找节点点击("管理网络", text("管理网络"), 1, 3100)) {
                        logd("管理网络")
                        sleep(20000)
                        back()
                        sleep(1000)
                        back()
                        sleep(1000)
                        back()
                        sleep(1000)
                        break
                    }

                }
            } else {
                toast("网络连接正常")
                sleep(2000)
                let url = "https://wdsanxingn8.oss-cn-beijing.aliyuncs.com/updete.txt"
                var 分解对象 = http.httpGetDefault(url, 10 * 1000, {"User-Agent": "test"});
                toast("当前版本 -> " + version);
                sleep(1000)
                toast("服务器版本 -> " + 分解对象);
                sleep(1000)
                var 分解对象为空 = utils.isObjectNull(分解对象);
                if (分解对象为空) {
                    sleep(2000)
                    logd("获取更新地址失败")
                    sleep(1000)
                    break
                } else {
                    if (version < 分解对象) {
                        logd("开始自动更新")
                        sleep(1000)
                        let 对象下载地址 = "https://wdsanxingn8.oss-cn-beijing.aliyuncs.com/release.iec"
                        if (对象下载地址 !== "") {

                            logd(对象下载地址)
                            let down = http.downloadFile(对象下载地址, "/sdcard/release.iec", 10 * 1000, {"User-Agent": "test"});
                            toast("下载:" + down);
                            sleep(2000);
                            zipFile = "/sdcard/release.iec"

                            sleep(2000);
                            let result = setIECPath("/sdcard/release.iec");
                            toast("result : " + result);
                            sleep(2000)
                            //开启定时任务准备下一次执行
                            let id2 = startJob("task2", "4", true);
                            toast("job id " + id2);
                            sleep(1000)
                            exit()
                        } else {
                            toast(对象地址);
                            sleep(2000)
                            break

                        }
                    } else {
                        toast("没有更新");
                        sleep(3000);
                        break

                    }

                }
                break;
            }
        }//热更新
        main()
    }

    function 查找节点点击(备注, 查找, 点击, 找寻时间) {
        let 节点 = 查找.getOneNodeInfo(找寻时间);
        if (节点) {
            if (点击 == 1) {
                节点.click()
                sleep(random(500, 1000));
            }
            if (点击 === 2) {
                节点.clickCenter();
                sleep(random(500, 1000));
            }
            if (点击 === 3) {
                节点.clickEx();
                sleep(random(500, 1000));
            }
            if (点击 === 4) {
                节点.longClick();
                sleep(random(500, 1000));
            }
            return true;
        }
        return false;
    }


    function 查找节点点击并输入(备注, 查找, 内容, 延迟时间) {
        let 节点 = 查找.getOneNodeInfo(延迟时间);
        if (节点) {
            节点.click()
            sleep(random(500, 1000));
            (节点).inputText(内容);
            sleep(random(500, 1000));
            return true;
        }
        return false;
    }

    function 找图点击(图片, 是否点击) {
        let bitmap = image.captureScreenBitmap("png", -1, 0, 0, 0, 100);
        let temp = image.readBitmap("/sdcard/找图/" + 图片 + ".png");
        let rects = imageHandler.findImgFast(bitmap, temp, 0.9, -1, 0, 0, 0, 10, true);
        if (rects) {
            if (是否点击 == 1) {
                clickPoint(rects[0].left, rects[0].top)
                sleep(1000)
            }
            imageHandler.recycle(bitmap, temp)
            sleep(100)
            return true;
        }
        imageHandler.recycle(bitmap, temp)
        sleep(100)
        return false;
    }


    function moveFun(qx, qy, zx, zy, time) {
        var xxy = [];
        var points = [];

        //设置控制点极限距离
        var leaveHeightLength = 500

        var point1 = {
            "x": qx,
            "y": qy
        };

        //根据偏差距离，应用不同的随机方式
        if (Math.abs(zx - qx) > Math.abs(zy - qy)) {
            var my = (qy + zy) / 2
            var y2 = my + random(0, leaveHeightLength)
            var y3 = my - random(0, leaveHeightLength)

            var lx = (qx - zx) / 3
            if (lx < 0) {
                lx = -lx
            }
            var x2 = qx + lx / 2 + random(0, lx)
            var x3 = qx + lx + lx / 2 + random(0, lx)
        } else {
            var mx = (qx + zx) / 2
            var y2 = mx + random(0, leaveHeightLength)
            var y3 = mx - random(0, leaveHeightLength)

            var ly = (qy - zy) / 3
            if (ly < 0) {
                ly = -ly
            }
            var y2 = qy + ly / 2 + random(0, ly)
            var y3 = qy + ly + ly / 2 + random(0, ly)
        }

        var point2 = {
            "x": x2,
            "y": y2
        };
        var point3 = {
            "x": x3,
            "y": y3,
        };
        var point4 = {
            "x": zx,
            "y": zy
        };


        points.push(point1);
        points.push(point2);
        points.push(point3);
        points.push(point4);

        let targetP;
        for (let i = 0; i < 1; i += 0.08) {
            targetP = bezier_curves(points, i);
            xxy.push([parseInt(targetP.x), parseInt(targetP.y)]);
        }

        let touch1 = [];
        let _time = time / xxy.length;

        touch1.push({"action": 0, "x": xxy[0][0], "y": xxy[0][1], "pointer": 1, "delay": _time})
        for (let i = 2; i < xxy.length - 1; i++) {
            touch1.push({"action": 2, "x": xxy[i][0], "y": xxy[i][1], "pointer": 1, "delay": _time})
        }
        touch1.push({
            "action": 1,
            "x": xxy[xxy.length - 1][0],
            "y": xxy[xxy.length - 1][1],
            "pointer": 1,
            "delay": _time
        })

        let x = multiTouch(touch1, null, null, 30000);
    };

    function bezier_curves(cp, t) {
        let cx = 3.0 * (cp[1].x - cp[0].x);
        let bx = 3.0 * (cp[2].x - cp[1].x) - cx;
        let ax = cp[3].x - cp[0].x - cx - bx;
        let cy = 3.0 * (cp[1].y - cp[0].y);
        let by = 3.0 * (cp[2].y - cp[1].y) - cy;
        let ay = cp[3].y - cp[0].y - cy - by;

        let tSquared = t * t;
        let tCubed = tSquared * t;
        let result = {
            "x": 0,
            "y": 0
        };
        result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
        result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
        return result;
    };


    function 停止应用(包名) {

        utils.openActivity({
            "action": "android.settings.APPLICATION_DETAILS_SETTINGS",
            "uri": "package:" + 包名
        });
        sleep(1000)
        if (查找节点点击("强制停止", text("强制停止"), 1, 1111)) {
            logd("强制停止")
            sleep(1000)
            if (查找节点点击("强制停止", text("强制停止"), 1, 1510)) {
                logd("强制停止")
                back()
                sleep(1000)
                back()
                sleep(1000)
                back()
                sleep(1000)
            }
        }
        if (查找节点点击("强行停止", text("强行停止"), 1, 1111)) {
            logd("强行停止")
            sleep(1010)
            if (查找节点点击("确定", text("确定"), 1, 1500)) {
                logd("确定")
                sleep(1010)
            }
            back()
            sleep(1000)
            back()
            sleep(1000)
            back()
            sleep(1000)
        }
    }

    function 检查图片(图片1) {
        let 本地图片 = 图片1
        let 图片是否存在 = file.exists("/sdcard/找图/" + 本地图片 + ".png");
        if (图片是否存在 == false) {
            let 图片下载地址 = "https://gitee.com/sun-jian-8341/tuse/raw/master/tuse/" + 本地图片 + ".png"
            if (图片下载地址 !== "") {
                let down = http.downloadFile(图片下载地址, "/sdcard/找图/" + 本地图片 + ".png", 10 * 1000, {"User-Agent": "test"});
                toast("下载:" + down);
                sleep(2000);
            }
            return true;
        }
        return false;
        sleep(100)
    }

